const session = {
  setObj: function(obj) {
    Object.keys(obj).forEach((key) => {
      session.set(key, obj[key])
    })
  },
  set: function(k, v) {
    try {
      sessionStorage.setItem(k, JSON.stringify(v))
    } catch (e) {
      console.log(e)
    }
  },
  get: function(k) {
    try {
      // JSON.parse报错说明不能转成对象，在catch中再return
      return JSON.parse(sessionStorage.getItem(k))
    } catch (e) {
      return sessionStorage.getItem(k)
    }
  },
  remove: function(k) {
    try {
      sessionStorage.removeItem(k)
    } catch (e) {
      console.log(e)
    }
  },
  clear: function() {
    try {
      sessionStorage.clear()
    } catch (e) {
      console.log(e)
    }
  }
}

export default session
